package com.kehongborui.fliggy.controller;

import com.kehongborui.fliggy.model.OrderModel;
import com.kehongborui.fliggy.model.VehicleModel;
import com.kehongborui.fliggy.service.OrderService;
import com.kehongborui.fliggy.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief 订单相关的页面
 * @email 122162005@qq.com
 * @date 2018-08-29
 */
@Controller
public class OrderPageController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private VehicleService vehicleService;

    /**
     * 根据列车编号，到达站，起点站跳转到填写订单的页面
     * @param vehicleModel
     * @param map
     * @param request
     * @return
     */
    @GetMapping("/{type}/to_open_order")
    public String openOrderPage(@PathVariable("type") String type, VehicleModel vehicleModel, ModelMap map, HttpServletRequest request) {
        // 查询车次信息
        map.addAttribute("vehicleModel", vehicleModel);
        return "openOrder";
    }


    @GetMapping("/confirm_order")
    public String confirmOrder(@RequestParam("orderid") String orderId, ModelMap map, HttpServletRequest request) {
        // 查询车次信息
        OrderModel orderModel = orderService.findById(orderId);
        VehicleModel vehicleModel = vehicleService.findById(orderModel.getVehicleId());
        map.addAttribute("orderModel", orderModel);
        map.addAttribute("vehicleModel", vehicleModel);
        return "confirmOrder";
    }
}
